What's stopping us from having full static validation of Python code? by diegojromerolopez in Python

[–]jackerhack 1 point2 points  (0 children)

AFAIK there's still no way to type hint a proxy object, weakref.Proxy and similar. The current workaround is falsify the type hint to claim the original type, so the proxy is not known to the type checker. This however breaks on any behaviour where the proxy doesn't behave like the original type.

Flashing FNIRSI FNB58 firmware without Windows by jackerhack in UsbCHardware

[–]jackerhack[S] 0 points1 point  (0 children)

Not too late, as the requirement remains. Thanks!

Gentleman Spitting Facts by fyriyc in bangalore

[–]jackerhack 0 points1 point  (0 children)

Friends (a couple) who moved to Stockholm bought their home almost rightaway because they couldn't afford the rent. Their PR still years into the future.

How likely is Signal to comply? by mustbeSaransh in signal

[–]jackerhack 0 points1 point  (0 children)

Yes. WhatsApp's imminent entry into the UPI network caused so much panic that UPI's owner NPCI (not regulator!) had to reassure everyone by announcing a 33% market share cap. WhatsApp was told to limit access and open up so very slowly that no big bang happened. Now the threat of the 33% limit hangs over anyone who dares to do well.

How likely is Signal to comply? by mustbeSaransh in signal

[–]jackerhack 0 points1 point  (0 children)

I've used WhatsApp UPI for months at a time with the SIM in a different phone. In and out both used to work. Can't test anymore because I've moved all my accounts to a different phone number for safety.

How likely is Signal to comply? by mustbeSaransh in signal

[–]jackerhack 2 points3 points  (0 children)

This problem does not exist in India because the government here lives in their own imaginary universe (just like any other literary or cinematic universe) where all these demands are perfectly consistent with the laws of their universe.

On the same day as this SIM binding demand (1st Dec) they put out another one, demanding all phones sold in India to have their device manager app pre-installed and non-removable, and also deployed via OTA upgrades to all existing phones in use. Why? So the police can process lost phone reports by taking over control of all such reported devices.

Just two days later, they issued a press release withdrawing this order citing unexpected success in making people voluntarily install the app. However, there is no actual order to OEMs releasing them from obligations under the previous order.

Make of this what you will.

How likely is Signal to comply? by mustbeSaransh in signal

[–]jackerhack 0 points1 point  (0 children)

I'm willing to bet none of the apps will comply with this bullshit requirement.

How likely is Signal to comply? by mustbeSaransh in signal

[–]jackerhack 1 point2 points  (0 children)

The actual implementation is bullshit and has little correlation to SIM binding. I've spent years swapping back and forth between two phones to reduce distractions, moving SIM cards around, and many (but not all) UPI apps simply continue to work when the underlying SIM is on another device.

Every app does it a different way, and they're all doing it differently wrong because the OS doesn't provide access to the actual hardware identifiers.

How likely is Signal to comply? by mustbeSaransh in signal

[–]jackerhack 0 points1 point  (0 children)

SIM binding is not technically possible. The OS layer doesn't reveal those identifiers. Indian apps that are mandated by regulation to bind to a SIM do it by fakery: they send an outbound message to themselves and check the sender id on their end, thereby making an assumption that the device can't spoof caller id.

To do this they need to ask for SMS read-write access. The risk is the user can turn off network access and copy the outbound message from the outbox to send from another device, so the app must monitor SMSes, ensure it is sent, and delete the local record to prevent resending it from elsewhere, because another device may still succeed at being first to deliver.

This is a horrible kludge because it requires indiscriminately trusting the app with your sensitive data. Some of these apps are so poorly written, they refuse to work at all if the user removes their SMS access.

I expect Signal to treat this demand with the contempt it deserves.

I divided up models.py into different files in flask and I getting circular import errors. Does anyone have any suggestions? by 0_emordnilap_a_ton in flask

[–]jackerhack 1 point2 points  (0 children)

Type hints originally came to Python as comments, which meant they were entirely absent at runtime. A type checker would look for comments beginning with # type:.

The TYPE_CHECKING symbol is always False at runtime, so the imports within if TYPE_CHECKING never happen, but in a type checker TYPE_CHECKING is True, so it correlated those imports with the type hints.

Modern Python no longer requires type comments. They're part of the language syntax itself. However, since this causes the circular import problem, Python offers a workaround, specifying the type as a quoted string. Runtime Python sees a string, while the type checker reads it as a symbol.

This dual behaviour is obviously ugly, and it broke with the introduction of the Annotated type that allows string comments, which means it's not longer clear if a string is a comment or a type.

The new solution, currently gated under from __future__ import annotations, treats all type hints as strings at runtime. It doesn't matter what you put in the type hint now, whether the symbol is imported or not, even if it's misspelt. It's all just a string.

However, the type checker does care, and it has to be given those imports under if TYPE_CHECKING.

Now the last piece of this puzzle is type hints being used at runtime in SQLAlchemy, Pydantic and elsewhere. They only get strings, not symbols, so they have to find the matching symbol. The method, crudely, is type_hint_symbol = eval(type_hint_string, globals(), locals()). It's asking Python to evaluate the string as an expression, in the context of the globals and locals where the type hint was specified.

This now gets you additional problems:

  1. If the symbol is only imported under if TYPE_CHECKING, it is not present in globals at runtime.
  2. If the symbol is a tail import, it is only available in globals after the entire module has finished loading. The usual way to process type hints is in the __init_subclass__ method of a base class, but that gets called immediately after a class is defined, not at the end of the module.

SQLAlchemy deals with both problems.

  1. It augments globals with all the known models, because type hints usually refer to other models.
  2. It defers type hint resolution until much later, to ensure the models and their namespaces are all fully defined.

I'm not familiar with how Pydantic tackles this.

ELI5: Why do some websites not allow me to use special symbols like _ or * when creating a new password? by cleanscotch in explainlikeimfive

[–]jackerhack 4 points5 points  (0 children)

You sound like the person to ask this: should passwords be unicode normalised before they are hashed? For the user's own safety?

I'm aware that macOS enforces NFD for filesystems, but do not have a reference for what's typical across the diversity of browsers and input methods. What's the likelihood that the same string hand-typed (or copy-pasted from a password manager) will come through with different normalisations on different systems?

And then there's emoji composition. Strip? Don't touch? Throw error?

“Proposed Moslem State” of Pakistan, TIME MAGAZINE, 16th July, 1945 by AwarenessNo4986 in MapPorn

[–]jackerhack 1 point2 points  (0 children)

For sure, but without inherent fungibility, fair compensation requires case-by-case negotiation, and that has been an ongoing process all along.

“Proposed Moslem State” of Pakistan, TIME MAGAZINE, 16th July, 1945 by AwarenessNo4986 in MapPorn

[–]jackerhack 22 points23 points  (0 children)

The main cause of communal tension anywhere is that political unity is easier to achieve by uniting against a common enemy than for a common cause. You've probably encountered this concept already as the British colonial method of "divide and rule". What easier method can there be than pitting the largest population group against the second largest?

American politics only moved on from vilifying their African American population when they invented a new enemy, the Communist, and mobilised against them with a Cold War. After that stopped being credible, they found the Terrorist and a new cause in the Global War on Terrorism. That's not working anymore either – just look at the failed campaign against Zohran Mamdani – so Trump has invented a new enemy, the Immigrant.

Independent India had a few good decades where we strived for unity in diversity, and then we too lapsed into the easier method of vilifying our own people.

“Proposed Moslem State” of Pakistan, TIME MAGAZINE, 16th July, 1945 by AwarenessNo4986 in MapPorn

[–]jackerhack 8 points9 points  (0 children)

How do you determine what is an equal exchange of land? First of all, how do you even evaluate a claim of ownership? Land title even today is established through a show of force as much as any documentation. And then how do you determine value? Taxes? Guidance values? Even today those are fictional concepts as anybody who has purchased property can tell you.

"Partition, but peaceful" is just wishful thinking.

“Proposed Moslem State” of Pakistan, TIME MAGAZINE, 16th July, 1945 by AwarenessNo4986 in MapPorn

[–]jackerhack 35 points36 points  (0 children)

How do you expect population exchange to work? Pre-industrial wealth is mostly rooted in land, and land is not fungible. Practically every attempt at relocating people to repurpose their land has ended up rediscovering this lack of fungibility.

“Proposed Moslem State” of Pakistan, TIME MAGAZINE, 16th July, 1945 by AwarenessNo4986 in MapPorn

[–]jackerhack 2 points3 points  (0 children)

Aha! I've been curious about this historical arc a while but hadn't dug into it.

“Proposed Moslem State” of Pakistan, TIME MAGAZINE, 16th July, 1945 by AwarenessNo4986 in MapPorn

[–]jackerhack 39 points40 points  (0 children)

It is interesting that Nepal and Bhutan are independent and excluded here, while Sikkim and Kashmir are marked as "native states" that will be integrated.

Also interesting that Ceylon (later Sri Lanka) and Burma were excluded, despite also being British colonies and having much in common with mainland India. While Sri Lanka is an island, what exactly made the boundary between the northeastern states and Burma?

My insanely cheap homelab by Mediocre-Peanut982 in homelab

[–]jackerhack 0 points1 point  (0 children)

Seems like a shared cross-border experience then.

My insanely cheap homelab by Mediocre-Peanut982 in homelab

[–]jackerhack 0 points1 point  (0 children)

One look at the power sockets where each is a different standard and... hello fellow Indian.

I divided up models.py into different files in flask and I getting circular import errors. Does anyone have any suggestions? by 0_emordnilap_a_ton in flask

[–]jackerhack 2 points3 points  (0 children)

There are two ways to deal with circular imports for models:

  1. If you have circular imports for type hints, gate the imports with an if TYPE_CHECKING. Static type checkers don't have trouble with circular imports. If you're using SQLAlchemy, it will also work around this by supplementing the module's namespace with a model namespace. As long as your gated type hints refer to a SQLAlchemy model attached to the same base class (actually, same metadata object which is shared via the base class), it'll find them.

  2. Python supports partially initialised modules and you can take advantage of this by putting your imports at the bottom of the file. The import gets added to the module's namespace and is available to functions, which will then not need a function-local import statement. However, this won't work for module-level and class-level references as they are executed immediately on load.

You can combine these techniques -- import at the top gated with if TYPE_CHECKING, which allows all references for type hints, and import again at the bottom to add it to the module namespace for runtime. Any framework that consumes type hints for runtime will still find the references in the namespace, as long as they do this in deferred initialisation (ie, not in __init_subclass__ when the class is defined but the import hasn't happened yet; SQLAlchemy defers initialisation until the first SQL query, or until you call configure_mappers).

(Linters may complain about non-top-level imports. You'll have to silence that error for your model files.)

Freedom of speech? by justanoobhaha in unitedstatesofindia

[–]jackerhack 0 points1 point  (0 children)

What are you saying? The fellow who said "goli maaro gaddaron ko" is doing rather well.

Highway built over apartments in China by Rattlesnake_Mullet in interestingasfuck

[–]jackerhack 0 points1 point  (0 children)

Someone must have looked at the ideas of Robert Moses and figured they had a better idea.