Skip to content

Commit

Permalink
Merge pull request #56 from jepperaskdk/pr/module-class-clash
Browse files Browse the repository at this point in the history
Fix module and class name clash
  • Loading branch information
jepperaskdk authored Aug 28, 2024
2 parents 5a52aa2 + 23224d3 commit 0fb7a61
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 2 deletions.
6 changes: 6 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## [0.2.1] - 2024-08-26

### Added

- Fixed bug where module and class name-clash would cause the wrong type to be compared.

## [0.2.0] - 2024-08-09

### Added
Expand Down
2 changes: 1 addition & 1 deletion pydoctest/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def get_type_from_module(type_string: str, module: ModuleType) -> LocateResult:
"""
# First let pydoc attempt to locate the type
located_type: Type = cast(Type, locate(type_string))
if located_type:
if located_type and not isinstance(located_type, ModuleType):
return LocateResult(located_type, 'locate')

# Try to eval it.
Expand Down
2 changes: 1 addition & 1 deletion pydoctest/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION = "0.2.0"
VERSION = "0.2.1"
14 changes: 14 additions & 0 deletions tests/test_class/method_with_module.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from datetime import datetime


def method_module_class_clash(date: datetime) -> datetime:
"""
This should work.
Args:
date (datetime): The date.
Returns:
datetime: [description]
"""
return date
9 changes: 9 additions & 0 deletions tests/test_class/test_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import tests.test_class.nodocstring_class
import tests.test_class.incorrect_class
import tests.test_class.raises_class
import tests.test_class.method_with_module


class TestDocs():
Expand Down Expand Up @@ -198,3 +199,11 @@ def test_raises_on_function_with_multiline_string(self) -> None:
config.fail_on_raises_section = True
result = validate_function(tests.test_class.raises_class.RaisesClass.func_with_raise_multiline_string, config, tests.test_class.incorrect_class)
assert result.result == ResultType.OK

def test_module_class_name_clash(self) -> None:
"""
Solves: https://github.com/jepperaskdk/pydoctest/issues/34.
"""
config = Configuration.get_default_configuration()
result = validate_function(tests.test_class.method_with_module.method_module_class_clash, config, tests.test_class.method_with_module)
assert result.result == ResultType.OK

0 comments on commit 0fb7a61

Please sign in to comment.