Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix _csv.Dialect.__init__ #12320

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Fix _csv.Dialect.__init__ #12320

wants to merge 2 commits into from

Conversation

sobolevn
Copy link
Member

@sobolevn sobolevn commented Jul 11, 2024

All props can be passed to __init__ as pos-or-keyword:

>>> _csv.Dialect(1)
<_csv.Dialect object at 0x106604d70>
>>> _csv.Dialect(dialect=1)
<_csv.Dialect object at 0x106605d90>

>>> _csv.Dialect(delimiter='.')
<_csv.Dialect object at 0x106605790>

>>> _csv.Dialect(quotechar='.')
<_csv.Dialect object at 0x106605970>
>>> _csv.Dialect(quotechar=None)
<_csv.Dialect object at 0x106605850>

Source: https://github.com/python/cpython/blame/e6264b44dc7221c713b14dfa0f5929b33d362829/Modules/_csv.c#L389

sobolevn and others added 2 commits July 11, 2024 12:59
All props can be passed to `__init__` as pos-or-keyword:

```python
>>> _csv.Dialect(1)
<_csv.Dialect object at 0x106604d70>
>>> _csv.Dialect(dialect=1)
<_csv.Dialect object at 0x106605d90>

>>> _csv.Dialect(delimiter='.')
<_csv.Dialect object at 0x106605790>

>>> _csv.Dialect(quotechar='.')
<_csv.Dialect object at 0x106605970>
>>> _csv.Dialect(quotechar=None)
<_csv.Dialect object at 0x106605850>
```
Copy link
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@sobolevn
Copy link
Member Author

Ok, I see: # actually csv.Dialect is a different class to _csv.Dialect at runtime, but for typing purposes, they're identical

@srittau
Copy link
Collaborator

srittau commented Jul 11, 2024

See #3613 for why this was added. csv.Dialect looks to be a weird hack at runtime, probably back from a time when C classes couldn't be sub-classed by Python code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants