- Notifications
You must be signed in to change notification settings - Fork263
Clarify namedtuple member rules#1979
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:main
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Conversation
Yes, please start a thread in the discussion forum. I don't think these changes will be controversial, but we should let the community weigh in. |
WSH032 commentedMay 18, 2025
Hi, I'm not sure if this is the right place for this discussion—if not, please let me know (and sorry!). I originally raisedthis issue in pyright, but I think here might be a more appropriate place to discuss it. Suppose I do have members that start with NT5=namedtuple("NT5", ["abc","_1"],rename=True)# OKNT5(abc="",_1=1)# OK How can I provide type annotations for them in a classNT5(NamedTuple):abc:str_1:int# <- HOW ?
|
I'm with Eric on the linked issue that this doesn't make sense to support. If you use different types on both arms of
No, unless the runtime has that exemption. We should match the runtime behavior.
Type checkers could do that but I don't think it should be the spec's business to decide how type checkers should proceed once they've detected a type error. |
And to give a constructive suggestion for your use case: Maybe just don't use namedtuple? If you require names that start with an underscore, it's not the right tool for the job. |
WSH032 commentedMay 18, 2025
Fair enough! Thanks for your quick response! 👍
It would be nice if
I can't control the code on the other end; I can only provide type annotations for it (like in a The workaround I've come up with for now is: classNT5(tuple[str,int]):abc:str_1:int__match_args__= ("abc","_1")def__new__(cls,abc:str,_1:int)->Self: ... But this isn't as straightforward as Anyway, thanks for your help! 🙏 |
* feat: add `ExitRequestApi` and `RunEvent::ExitRequested::api` field* refactor: move `PhysicalPositionF64` to `ext_mod::lib`* feat: add `CloseRequestApi`* feat: add `Theme` and `AppHandle/WebviewWindow::{theme, set_theme}`* feat: add `_NonExhaustive` field to all `#[non_exhaustive]` enums* feat: add `DragDropEvent` and `DragDropEventType`* feat!: `Position.Physical(x, y)` -> `Position.Physical(tuple(x, y))`changed:- `Position.Physical`- `Position.Logical`- `Size.Physical`- `Size.Logical`migration:```pyfrom pytauri import Position, PositionType, Size, SizeTypedef old(pos: PositionType, size: SizeType) -> None: match pos: case Position.Physical(x, y): print(f"Physical position: {x}, {y}") case Position.Logical(x, y): print(f"Logical position: {x}, {y}") match size: case Size.Physical(w, h): print(f"Physical size: {w}, {h}") case Size.Logical(w, h): print(f"Logical size: {w}, {h}")old(pos=Position.Physical(1, 2), size=Size.Physical(3, 4))def new(pos: PositionType, size: SizeType) -> None: match pos: case Position.Physical((x, y)): print(f"Physical position: {x}, {y}") case Position.Logical((x, y)): print(f"Logical position: {x}, {y}") match size: case Size.Physical((w, h)): print(f"Physical size: {w}, {h}") case Size.Logical((w, h)): print(f"Logical size: {w}, {h}")new(pos=Position.Physical((1, 2)), size=Size.Physical((3, 4)))```* feat: add `WebviewEvent`, `WebviewEventType`added:- `WebviewEvent`- `WebviewEventType`- `RunEvent.WebviewEvent.event` field- `webview.WebviewWindow.on_webview_event` method* feat: add `WindowEvent`, `WindowEventType`added:- `WindowEvent`- `WindowEventType`- `RunEvent.WindowEvent.event` field- `webview.WebviewWindow.on_window_event` method* fix: namedtuple member name can't start with underscoreref: <python/typing#1979 (comment)>* docs: changelog
The change looks good to me, but you'll need to update the branch, resolve merge conflicts, and re-run the tests with the latest versions of the type checkers. Thanks for the contribution! |
Ok, I've rebased and updated the results. |
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
This PR clarifies the typing spec around named tuple fields and adds a few conformance test cases:
rename
)Analogous restrictions are outlined in thespec for enums, but they are not present in the spec for named tuples.
Since this is adding new rules to the spec, should I open a discussion in the forum about it?