Skip to content

Commit

Permalink
Update codegen & docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxim Avanov committed Apr 22, 2019
1 parent 4e16fd7 commit 39a1558
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion docs/quickstart_guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ You should see output similar to this:
}
mk_main, dict_main = type_constructor(Main, overrides)
mk_main, dict_main = type_constructor & overrides ^ Main
You can use this snippet as a starting point to improve further.
Expand Down
5 changes: 3 additions & 2 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ def test_cli(stdin_data):
m_stdin.read.return_value = stdin_data
main(['gen'])
m_exit.assert_called_once_with(0)
test_str = 'mk_main, dict_main = type_constructor(Main)'
assert test_str in str(m_stdout.write.mock_calls[0])
test_str = 'mk_main, dict_main = type_constructor ^ Main'
code_snippet = str(m_stdout.write.mock_calls[0][1][0])
assert test_str in code_snippet
12 changes: 8 additions & 4 deletions typeit/codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,18 @@ def codegen_py(typ: Type[iface.IType],
LINE_SKIP,
f'mk_{inflection.underscore(typ.__name__)}, '
f'dict_{inflection.underscore(typ.__name__)} = '
f'type_constructor({typ.__name__}, overrides)'
f'type_constructor & overrides ^ {typ.__name__}',
LINE_SKIP,
])
else:
code.append(
code.extend([
LINE_SKIP,
LINE_SKIP,
f'mk_{inflection.underscore(typ.__name__)}, '
f'dict_{inflection.underscore(typ.__name__)} = '
f'type_constructor({typ.__name__})'
)
f'type_constructor ^ {typ.__name__}',
LINE_SKIP,
])

code = [
'from typing import NamedTuple, Dict, Any, List, Optional',
Expand Down
2 changes: 1 addition & 1 deletion typeit/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ def __and__(self, override: OverrideT) -> '_TypeConstructor':
overrides = self.overrides.update(override)
return self.__class__(overrides=overrides)

def __xor__(self, typ: Type) -> TypeTools:
def __xor__(self, typ: Type[T]) -> TypeTools:
return self.__call__(typ, self.overrides)


Expand Down

0 comments on commit 39a1558

Please sign in to comment.