Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix stuff
- Fix variable names
- Add NullType
- Fix instance check
  • Loading branch information
erlend-aasland committed May 18, 2023
commit d145ff881c48d7a7c77cf59d975911100d1f3508
27 changes: 21 additions & 6 deletions Tools/clinic/clinic.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,15 @@

from collections.abc import Callable
from types import FunctionType, NoneType
from typing import Any, Final, NamedTuple, NoReturn, Literal, overload
from typing import (
Any,
Final,
Literal,
NamedTuple,
NoReturn,
Type,
overload,
)

# TODO:
#
Expand Down Expand Up @@ -73,6 +81,8 @@ def __repr__(self) -> str:
NULL: Final = Sentinels.NULL
unknown: Final = Sentinels.unknown

NullType = type(Sentinels.NULL)

sig_end_marker = '--'

Appender = Callable[[str], None]
Expand Down Expand Up @@ -2694,7 +2704,12 @@ def __init__(self,
self.unused = unused

if default is not unspecified:
if self.default_type and not isinstance(default, (self.default_type, Unknown)):
if (self.default_type
and not (
isinstance(default, self.default_type)
or default is unknown
)
):
if isinstance(self.default_type, type):
types_str = self.default_type.__name__
else:
Expand Down Expand Up @@ -3482,7 +3497,7 @@ def str_converter_key(types, encoding, zeroes):

class str_converter(CConverter):
type = 'const char *'
default_type = (str, Null, NoneType)
default_type = (str, NullType, NoneType)
format_unit = 's'

def converter_init(
Expand All @@ -3501,7 +3516,7 @@ def converter_init(
self.format_unit = format_unit
self.length = bool(zeroes)
if encoding:
if self.default not in (Null, None, unspecified):
if self.default not in (NULL, None, unspecified):
fail("str_converter: Argument Clinic doesn't support default values for encoded strings")
self.encoding = encoding
self.type = 'char *'
Expand Down Expand Up @@ -3649,7 +3664,7 @@ def parse_arg(self, argname: str, displayname: str) -> str:

class unicode_converter(CConverter):
type = 'PyObject *'
default_type = (str, Null, NoneType)
default_type = (str, NullType, NoneType)
format_unit = 'U'

def parse_arg(self, argname: str, displayname: str) -> str:
Expand All @@ -3673,7 +3688,7 @@ def parse_arg(self, argname: str, displayname: str) -> str:
@add_legacy_c_converter('Z#', accept={str, NoneType}, zeroes=True)
class Py_UNICODE_converter(CConverter):
type = 'const Py_UNICODE *'
default_type = (str, Null, NoneType)
default_type = (str, NullType, NoneType)

def converter_init(
self, *,
Expand Down