Skip to content

[mypy] Fixes typing errors in other/dpll #5801

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

Closed
wants to merge 1 commit into from

Conversation

spazm
Copy link
Contributor

@spazm spazm commented Nov 10, 2021

Describe your change:

  • As per usage examples, clause literals are a list of strings.
    • Note: symbols extracted from literals are expected to be exactly two characters.
  • self.literal boolean values are initialized to None, so must be optional
  • model values should be Booleans, but aren't guaranteed to be non-None
    in the code.
  • uses newer '... | None' annotation for Optional values
  • clauses are passed to the Formula initializer as both lists and sets, they
    are stored as lists. Returned clauses will always be lists.
  • use explicit tuple annotation from future rather than using (..., ...)
    in return signatures
  • mapping returned by dpll_algorithm is optional per the documentation.

Related to #4052

Before

% git checkout master
Switched to branch 'master'

% mypy ./davisb_putnamb_logemannb_loveland.py
davisb_putnamb_logemannb_loveland.py:43: error: Argument 1 to "join" of "str" has incompatible type "Dict[int, None]"; expected "Iterable[str]"
davisb_putnamb_logemannb_loveland.py:60: error: Value of type "int" is not indexable
davisb_putnamb_logemannb_loveland.py:67: error: "int" has no attribute "endswith"
davisb_putnamb_logemannb_loveland.py:69: error: Incompatible types in assignment (expression has type "bool", target has type "None")
davisb_putnamb_logemannb_loveland.py:81: error: "int" has no attribute "rstrip"
davisb_putnamb_logemannb_loveland.py:81: error: "int" has no attribute "endswith"
davisb_putnamb_logemannb_loveland.py:81: error: Unsupported operand types for + ("int" and "str")
davisb_putnamb_logemannb_loveland.py:88: error: Incompatible return value type (got "None", expected "bool")
davisb_putnamb_logemannb_loveland.py:135: error: Argument 1 to "Clause" has incompatible type "List[str]"; expected "List[int]"
davisb_putnamb_logemannb_loveland.py:142: error: Need type annotation for "clauses" (hint: "clauses: Set[<type>] = ...")
davisb_putnamb_logemannb_loveland.py:146: error: Argument 1 to "Formula" has incompatible type "Set[Clause]"; expected "List[Clause]"
davisb_putnamb_logemannb_loveland.py:149: error: Syntax error in type annotation
davisb_putnamb_logemannb_loveland.py:149: note: Suggestion: Use Tuple[T1, ..., Tn] instead of (T1, ..., Tn)
davisb_putnamb_logemannb_loveland.py:169: error: Value of type "int" is not indexable
davisb_putnamb_logemannb_loveland.py:177: error: Syntax error in type annotation
davisb_putnamb_logemannb_loveland.py:177: note: Suggestion: Use Tuple[T1, ..., Tn] instead of (T1, ..., Tn)
davisb_putnamb_logemannb_loveland.py:201: error: Need type annotation for "assignment" (hint: "assignment: Dict[<type>, <type>] = ...")
davisb_putnamb_logemannb_loveland.py:229: error: Syntax error in type annotation
davisb_putnamb_logemannb_loveland.py:229: note: Suggestion: Use Tuple[T1, ..., Tn] instead of (T1, ..., Tn)
davisb_putnamb_logemannb_loveland.py:268: error: Value of type "int" is not indexable
davisb_putnamb_logemannb_loveland.py:269: error: Argument 1 to "len" has incompatible type "int"; expected "Sized"
davisb_putnamb_logemannb_loveland.py:270: error: Value of type "int" is not indexable
davisb_putnamb_logemannb_loveland.py:277: error: Syntax error in type annotation
davisb_putnamb_logemannb_loveland.py:277: note: Suggestion: Use Tuple[T1, ..., Tn] instead of (T1, ..., Tn)
Found 20 errors in 1 file (checked 1 source file)

After

% git checkout -
Switched to branch 'mypy-fix-other-davisb'
Your branch is up to date with 'origin/mypy-fix-other-davisb'.

% mypy ./davisb_putnamb_logemannb_loveland.py 
Success: no issues found in 1 source file
% mypy --strict ./davisb_putnamb_logemannb_loveland.py
Success: no issues found in 1 source file
  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Documentation change?

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation.
  • If this pull request resolves one or more open issues then the commit message contains Fixes: #{$ISSUE_NO}.

+ As per usage examples, clause literals are a list of strings.
  + Note: symbols extracted from literals are expected to be exactly two characters.
+ self.literal boolean values are initialized to None, so must be optional
+ model values should be Booleans, but aren't guaranteed to be non-None
  in the code.
+ uses newer '... | None' annotation for Optional values
+ clauses are passed to the Formula initializer as both lists and sets, they
  are stored as lists.  Returned clauses will always be lists.
+ use explicit tuple annotation from __future__  rather than using (..., ...)
  in return signatures
+ mapping returned by dpll_algorithm is optional per the documentation.
@ghost ghost added awaiting reviews This PR is ready to be reviewed enhancement This PR modified some existing files labels Nov 10, 2021
@spazm
Copy link
Contributor Author

spazm commented Nov 10, 2021

originally #5648

Copy link
Contributor

@dylanbuchi dylanbuchi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your pull request was merged here: #5759
@spazm

@spazm
Copy link
Contributor Author

spazm commented Nov 10, 2021 via email

@dylanbuchi
Copy link
Contributor

No problem! You can close this PR now. @spazm

@poyea poyea closed this Nov 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting reviews This PR is ready to be reviewed enhancement This PR modified some existing files
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants