Skip to content

Commit

Permalink
Fix _csv.Dialect.__init__ (#12320)
Browse files Browse the repository at this point in the history
  • Loading branch information
sobolevn authored Oct 3, 2024
1 parent 848cf91 commit d16fe74
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
1 change: 0 additions & 1 deletion stdlib/@tests/stubtest_allowlists/common.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ _collections_abc.AsyncGenerator.ag_running
_collections_abc.ItemsView.__reversed__
_collections_abc.KeysView.__reversed__
_collections_abc.ValuesView.__reversed__
_csv.Dialect.__init__ # C __init__ signature is inaccurate
_ctypes.CFuncPtr # stubtest erroneously thinks it can't be subclassed
_threading_local.local.__new__
ast.Bytes.__new__
Expand Down
17 changes: 14 additions & 3 deletions stdlib/_csv.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ _QuotingType: TypeAlias = int

class Error(Exception): ...

_DialectLike: TypeAlias = str | Dialect | type[Dialect]

class Dialect:
delimiter: str
quotechar: str | None
Expand All @@ -29,9 +31,18 @@ class Dialect:
lineterminator: str
quoting: _QuotingType
strict: bool
def __init__(self) -> None: ...

_DialectLike: TypeAlias = str | Dialect | type[Dialect]
def __init__(
self,
dialect: _DialectLike | None = ...,
delimiter: str = ",",
doublequote: bool = True,
escapechar: str | None = None,
lineterminator: str = "\r\n",
quotechar: str | None = '"',
quoting: _QuotingType = 0,
skipinitialspace: bool = False,
strict: bool = False,
) -> None: ...

class _reader(Iterator[list[str]]):
@property
Expand Down
7 changes: 4 additions & 3 deletions stdlib/csv.pyi
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import sys

# actually csv.Dialect is a different class to _csv.Dialect at runtime, but for typing purposes, they're identical
from _csv import (
QUOTE_ALL as QUOTE_ALL,
QUOTE_MINIMAL as QUOTE_MINIMAL,
QUOTE_NONE as QUOTE_NONE,
QUOTE_NONNUMERIC as QUOTE_NONNUMERIC,
Dialect as Dialect,
Dialect as _Dialect,
Error as Error,
__version__ as __version__,
_DialectLike,
Expand Down Expand Up @@ -61,6 +59,9 @@ if sys.version_info < (3, 13):

_T = TypeVar("_T")

class Dialect(_Dialect):
def __init__(self) -> None: ...

class excel(Dialect): ...
class excel_tab(excel): ...
class unix_dialect(Dialect): ...
Expand Down

0 comments on commit d16fe74

Please sign in to comment.