From 548d85a27ffcbad7edd68d7f8552bc2dda9807f9 Mon Sep 17 00:00:00 2001 From: Tom Parker-Shemilt Date: Mon, 14 Nov 2022 15:55:41 +0000 Subject: [PATCH] Fix implicit Optional issues (#1748) * Move show-column-numbers into config * Fix various implicit Optional issues --- .github/workflows/ci.yml | 2 +- faker/factory.py | 2 +- faker/providers/__init__.py | 2 +- faker/providers/date_time/__init__.py | 2 +- faker/providers/lorem/__init__.py | 4 ++-- faker/providers/misc/__init__.py | 4 ++-- mypy.ini | 3 ++- 7 files changed, 10 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4b1c7781fb..04feacb1cb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -162,7 +162,7 @@ jobs: uses: liskin/gh-problem-matcher-wrap@v1 with: linters: mypy - run: mypy --show-column-numbers --install-types --non-interactive --config mypy.ini faker + run: mypy --install-types --non-interactive --config mypy.ini faker test_ubuntu: runs-on: ubuntu-latest diff --git a/faker/factory.py b/faker/factory.py index 56f477481c..1f66b93fd8 100644 --- a/faker/factory.py +++ b/faker/factory.py @@ -25,7 +25,7 @@ def create( cls, locale: Optional[str] = None, providers: Optional[List[str]] = None, - generator: Generator = None, + generator: Optional[Generator] = None, includes: Optional[List[str]] = None, # Should we use weightings (more realistic) or weight every element equally (faster)? # By default, use weightings for backwards compatibility & realism diff --git a/faker/providers/__init__.py b/faker/providers/__init__.py index 44ec66138a..f5705b6d77 100644 --- a/faker/providers/__init__.py +++ b/faker/providers/__init__.py @@ -22,7 +22,7 @@ class BaseProvider: __provider__ = "base" - __lang__ = None + __lang__: Optional[str] = None __use_weighting__ = False # Locales supported by Linux Mint from `/usr/share/i18n/SUPPORTED` diff --git a/faker/providers/date_time/__init__.py b/faker/providers/date_time/__init__.py index 016b11ee80..c8d9f360ce 100644 --- a/faker/providers/date_time/__init__.py +++ b/faker/providers/date_time/__init__.py @@ -1900,7 +1900,7 @@ def date(self, pattern: str = "%Y-%m-%d", end_datetime: Optional[DateParseType] """ return self.date_time(end_datetime=end_datetime).strftime(pattern) - def date_object(self, end_datetime: datetime = None) -> dtdate: + def date_object(self, end_datetime: Optional[datetime] = None) -> dtdate: """ Get a date object between January 1, 1970 and now :example: datetime.date(2016, 9, 20) diff --git a/faker/providers/lorem/__init__.py b/faker/providers/lorem/__init__.py index 65217f4cd7..f730415764 100644 --- a/faker/providers/lorem/__init__.py +++ b/faker/providers/lorem/__init__.py @@ -26,7 +26,7 @@ class Provider(BaseProvider): def words( self, nb: int = 3, - part_of_speech: str = None, + part_of_speech: Optional[str] = None, ext_word_list: Optional[Sequence[str]] = None, unique: bool = False, ) -> List[str]: @@ -73,7 +73,7 @@ def words( samples = cast(List[str], self.random_choices(word_list, length=nb)) return samples - def word(self, part_of_speech: str = None, ext_word_list: Optional[Sequence[str]] = None) -> str: + def word(self, part_of_speech: Optional[str] = None, ext_word_list: Optional[Sequence[str]] = None) -> str: """Generate a word. This method uses |words| under the hood with the ``nb`` argument set to diff --git a/faker/providers/misc/__init__.py b/faker/providers/misc/__init__.py index 6be1b657cb..aea4bf73f2 100644 --- a/faker/providers/misc/__init__.py +++ b/faker/providers/misc/__init__.py @@ -488,7 +488,7 @@ def psv( delimiter="|", ) - def json(self, data_columns: List = None, num_rows: int = 10, indent: int = None) -> str: + def json(self, data_columns: Optional[List] = None, num_rows: int = 10, indent: Optional[int] = None) -> str: """ Generate random JSON structure values. @@ -590,7 +590,7 @@ def create_json_structure(data_columns: Union[Dict, List]) -> dict: data = [create_json_structure(data_columns) for _ in range(num_rows)] return json.dumps(data, indent=indent) - def fixed_width(self, data_columns: list = None, num_rows: int = 10, align: str = "left") -> str: + def fixed_width(self, data_columns: Optional[list] = None, num_rows: int = 10, align: str = "left") -> str: """ Generate random fixed width values. diff --git a/mypy.ini b/mypy.ini index ff7ed1fc46..3b6f0a18f7 100644 --- a/mypy.ini +++ b/mypy.ini @@ -8,4 +8,5 @@ allow_redefinition = True pretty = True follow_imports=silent ignore_missing_imports = True -show_error_codes = True \ No newline at end of file +show_error_codes = True +show_column_numbers = True \ No newline at end of file