Skip to content

Conversation

@gmorales96
Copy link
Contributor

@gmorales96 gmorales96 commented Aug 12, 2025

Summary by CodeRabbit

  • New Features

    • Parses birthdate text into a nullable date property (None for missing/invalid values).
    • Adds a matching check to compare birthdate or CURP with provided values.
  • Bug Fixes / Improvements

    • Normalizes extra-data keys to lowercase when collected.
  • Tests

    • Expanded, parameterized coverage for birthdate parsing and matching logic.
  • Chores

    • Version bumped to 1.0.2.

@coderabbitai
Copy link

coderabbitai bot commented Aug 12, 2025

Walkthrough

  • quienesquien/person.py: added import datetime as dt; changed peso1 to use only @computed_field; added @property fecha_nacimiento_to_date(self) -> dt.date | None that parses fecha_nacimiento with '%d/%m/%Y' (returns None on missing/parse errors); collect_extra_fields now normalizes model_extra keys to lowercase; added matches_data(self, date_of_birth: dt.date | None = None, curp: str | None = None) -> bool comparing the parsed date and self.curp to inputs.
  • quienesquien/version.py: bumped __version__ from '1.0.1' to '1.0.2'.
  • tests/test_person.py: added imports and type hints, adjusted extra-field assertions to use lowercase model_extra keys, and added parameterized tests for fecha_nacimiento_to_date and matches_data.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.


📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 1f66684 and e940e79.

📒 Files selected for processing (1)
  • quienesquien/version.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • quienesquien/version.py
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch enhancement-qeq-integration

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@codecov
Copy link

codecov bot commented Aug 12, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (534f792) to head (e940e79).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##            master       #11   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            6         6           
  Lines          156       169   +13     
=========================================
+ Hits           156       169   +13     
Flag Coverage Δ
unittests 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (5)
quienesquien/person.py (4)

32-36: Add return_type to computed_field for JSON schema accuracy.

Declare the output type to ensure correct schema generation and downstream tooling.

-    @computed_field
+    @computed_field(return_type=str)
     def peso1(self) -> str:
         # peso1 is required for backward compatibility with previous version.
         return str(self.coincidencia)

37-47: Also add return_type for fecha_nacimiento_date.

This helps expose the correct type in the model schema.

-    @computed_field
+    @computed_field(return_type=dt.date)
     def fecha_nacimiento_date(self) -> dt.date | None:
         if not self.fecha_nacimiento:
             return None
         try:
             return dt.datetime.strptime(
                 self.fecha_nacimiento, '%d/%m/%Y'
             ).date()
-        except (TypeError, ValueError):
+        except (ValueError):
             return None

Note: TypeError is unlikely after the truthiness check and Pydantic's coercion to str; catching ValueError should suffice.


68-71: Simplify final return (Ruff SIM103).

Replace the if/return/else with a direct boolean return.

-        if curp and self.curp and curp != self.curp:
-            return True
-
-        return False
+        return bool(curp and self.curp and curp != self.curp)

58-71: Optional: Normalize CURP comparison (trim and uppercase) to avoid false mismatches.

Data often varies in case and surrounding whitespace. Normalizing reduces false positives without changing intended semantics.

     def is_potential_false_positive(
         self, date_of_birth: dt.date | None = None, curp: str | None = None
     ) -> bool:
         if (
             date_of_birth
             and self.fecha_nacimiento_date is not None
             and self.fecha_nacimiento_date != date_of_birth
         ):
             return True

-        return bool(curp and self.curp and curp != self.curp)
+        curp_normalized = curp.strip().upper() if curp else None
+        self_curp_normalized = (
+            self.curp.strip().upper() if self.curp else None
+        )
+        return bool(
+            curp_normalized
+            and self_curp_normalized
+            and curp_normalized != self_curp_normalized
+        )

If you adopt this, consider adding/adjusting tests to cover case/whitespace variations for CURP.

tests/test_person.py (1)

57-93: Solid scenario matrix for is_potential_false_positive; consider adding ids for readability.

Parametrized cases are comprehensive. Adding ids improves test output readability when cases fail.

 @pytest.mark.parametrize(
     'p_nacimiento, p_curp, input_date, input_curp, expected_result',
-    [
+    [
         # Different birth dates - should be potential false positive
         ('13/11/1953', None, dt.date(1953, 11, 14), None, True),
         # Same birth dates - should not be potential false positive
         ('13/11/1953', None, dt.date(1953, 11, 13), None, False),
         # Different CURPs - should be potential false positive
         (None, 'LOOA531113HDFPBR07', None, 'DIFFERENT_CURP_123', True),
         # Same CURPs - should not be potential false positive
         (None, 'LOOA531113HDFPBR07', None, 'LOOA531113HDFPBR07', False),
         # Both date and CURP different - should be potential false positive
         (
             '13/11/1953',
             'LOOA531113HDFPBR07',
             dt.date(1953, 11, 14),
             'DIFFERENT_CURP_123',
             True,
         ),
         # Both date and CURP same - should not be potential false positive
         (
             '13/11/1953',
             'LOOA531113HDFPBR07',
             dt.date(1953, 11, 13),
             'LOOA531113HDFPBR07',
             False,
         ),
         # No data to compare - should not be potential false positive
         (None, None, None, None, False),
         # Person has data but no input data - should not be false positive
         ('13/11/1953', None, None, None, False),
         (None, 'LOOA531113HDFPBR07', None, None, False),
         ('13/11/1953', 'LOOA531113HDFPBR07', None, None, False),
         # Input data but person has no data - should not be false positive
         (None, None, dt.date(1953, 11, 13), 'LOOA531113HDFPBR07', False),
-    ],
+    ],
+    ids=lambda p: f"p_dob={p[0]}_p_curp={p[1]}_in_dob={p[2]}_in_curp={p[3]}_res={p[4]}",
 )

If you adopt CURP normalization, add one case asserting that differing case/whitespace does not trigger a false positive.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 534f792 and 92f815a.

📒 Files selected for processing (3)
  • quienesquien/person.py (3 hunks)
  • quienesquien/version.py (1 hunks)
  • tests/test_person.py (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.py

⚙️ CodeRabbit Configuration File

**/*.py: Enforce Relative Imports for Internal Modules

Ensure that any imports referencing internal modules use relative paths. However, if modules reside in the main module directories (for example /src or /library_or_app_name) —and relative imports are not feasible—absolute imports are acceptable. Additionally, if a module is located outside the main module structure (for example, in /tests or /scripts at a similar level), absolute imports are also valid.

Examples and Guidelines:

  1. If a module is in the same folder or a subfolder of the current file, use relative imports. For instance: from .some_module import SomeClass
  2. If the module is located under /src or /library_or_app_name and cannot be imported relatively, absolute imports are allowed (e.g., from library_or_app_name.utilities import helper_method).
  3. If a module is outside the main module directories (for example, in /tests, /scripts, or any similarly placed directory), absolute imports are valid.
  4. External (third-party) libraries should be imported absolutely (e.g., import requests).

**/*.py:
Rule: Enforce Snake Case in Python Backend

  1. New or Modified Code: Use snake_case for all variables, functions, methods, and class attributes.
  2. Exceptions (Pydantic models for API responses):
    • Primary fields must be snake_case.
    • If older clients expect camelCase, create a computed or alias field that references the snake_case field.
    • Mark any camelCase fields as deprecated or transitional.

Examples

Invalid:

class CardConfiguration(BaseModel):
    title: str
    subTitle: str  # ❌ Modified or new field in camelCase

Valid:

class CardConfiguration(BaseModel):
    title: str
    subtitle: str  # ✅ snake_case for new/modified field

    @computed_field
    def subTitle(self) -> str:  # camelCase allowed only for compatibility
        return self.subtitle

Any direct use of camelCase in new or updated code outside of these exceptions should be flagged.

`*...

Files:

  • quienesquien/version.py
  • quienesquien/person.py
  • tests/test_person.py
🪛 Ruff (0.12.2)
quienesquien/person.py

68-71: Return the condition bool(curp and self.curp and curp != self.curp) directly

Replace with return bool(curp and self.curp and curp != self.curp)

(SIM103)

🔇 Additional comments (3)
quienesquien/version.py (1)

1-1: LGTM: Version bump aligns with newly added public API.

The dev version increment is appropriate given the new computed field and method additions.

tests/test_person.py (2)

9-26: LGTM: Extra fields assertions reflect Pydantic v2 behavior.

Validating lowercase keys via model_extra is correct and future-proof.


29-55: Good parameter coverage for fecha_nacimiento parsing.

Covers happy path and multiple failure modes.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
quienesquien/person.py (2)

37-47: Trim whitespace before parsing date to reduce spurious parse failures

Inputs with trailing/leading spaces (e.g., "01/01/2000 ") will currently raise and return None. Stripping before parsing is safer and keeps behavior lenient without changing the API.

Apply this diff:

 @property
 def fecha_nacimiento_date(self) -> dt.date | None:
-    if not self.fecha_nacimiento:
+    raw = self.fecha_nacimiento
+    if not raw:
         return None
     try:
-        return dt.datetime.strptime(
-            self.fecha_nacimiento, '%d/%m/%Y'
-        ).date()
+        return dt.datetime.strptime(raw.strip(), '%d/%m/%Y').date()
     except (TypeError, ValueError):
         return None

58-71: Simplify boolean return, avoid double parsing, and address Ruff SIM103

  • Return the condition directly (addresses Ruff SIM103).
  • Cache fecha_nacimiento_date to avoid parsing twice.
  • Behavior remains identical.

Apply this diff:

 def is_potential_false_positive(
     self, date_of_birth: dt.date | None = None, curp: str | None = None
 ) -> bool:
-    if (
-        date_of_birth
-        and self.fecha_nacimiento_date is not None
-        and self.fecha_nacimiento_date != date_of_birth
-    ):
-        return True
-
-    if curp and self.curp and curp != self.curp:
-        return True
-
-    return False
+    dob = self.fecha_nacimiento_date
+    return bool(
+        (date_of_birth and dob is not None and dob != date_of_birth)
+        or (curp and self.curp and curp != self.curp)
+    )

Optional (confirm intent first): If CURP can arrive with inconsistent casing/spacing or empty strings, consider normalizing to reduce false mismatches:

 def is_potential_false_positive(
     self, date_of_birth: dt.date | None = None, curp: str | None = None
 ) -> bool:
-    dob = self.fecha_nacimiento_date
-    return bool(
-        (date_of_birth and dob is not None and dob != date_of_birth)
-        or (curp and self.curp and curp != self.curp)
-    )
+    dob = self.fecha_nacimiento_date
+    # Normalize CURP values if provided
+    curp_norm = (curp or "").strip().upper()
+    self_curp_norm = (self.curp or "").strip().upper()
+    return bool(
+        (date_of_birth and dob is not None and dob != date_of_birth)
+        or (curp_norm and self_curp_norm and curp_norm != self_curp_norm)
+    )

Please confirm:

  • Do upstream sources ever send lowercase or whitespace-padded CURPs?
  • Should empty strings be treated as “unknown” (current truthiness check ignores them)?
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 92f815a and 7e769af.

📒 Files selected for processing (2)
  • quienesquien/person.py (3 hunks)
  • quienesquien/version.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • quienesquien/version.py
🧰 Additional context used
📓 Path-based instructions (1)
**/*.py

⚙️ CodeRabbit Configuration File

**/*.py: Enforce Relative Imports for Internal Modules

Ensure that any imports referencing internal modules use relative paths. However, if modules reside in the main module directories (for example /src or /library_or_app_name) —and relative imports are not feasible—absolute imports are acceptable. Additionally, if a module is located outside the main module structure (for example, in /tests or /scripts at a similar level), absolute imports are also valid.

Examples and Guidelines:

  1. If a module is in the same folder or a subfolder of the current file, use relative imports. For instance: from .some_module import SomeClass
  2. If the module is located under /src or /library_or_app_name and cannot be imported relatively, absolute imports are allowed (e.g., from library_or_app_name.utilities import helper_method).
  3. If a module is outside the main module directories (for example, in /tests, /scripts, or any similarly placed directory), absolute imports are valid.
  4. External (third-party) libraries should be imported absolutely (e.g., import requests).

**/*.py:
Rule: Enforce Snake Case in Python Backend

  1. New or Modified Code: Use snake_case for all variables, functions, methods, and class attributes.
  2. Exceptions (Pydantic models for API responses):
    • Primary fields must be snake_case.
    • If older clients expect camelCase, create a computed or alias field that references the snake_case field.
    • Mark any camelCase fields as deprecated or transitional.

Examples

Invalid:

class CardConfiguration(BaseModel):
    title: str
    subTitle: str  # ❌ Modified or new field in camelCase

Valid:

class CardConfiguration(BaseModel):
    title: str
    subtitle: str  # ✅ snake_case for new/modified field

    @computed_field
    def subTitle(self) -> str:  # camelCase allowed only for compatibility
        return self.subtitle

Any direct use of camelCase in new or updated code outside of these exceptions should be flagged.

`*...

Files:

  • quienesquien/person.py
🪛 Ruff (0.12.2)
quienesquien/person.py

68-71: Return the condition bool(curp and self.curp and curp != self.curp) directly

Replace with return bool(curp and self.curp and curp != self.curp)

(SIM103)

🔇 Additional comments (2)
quienesquien/person.py (2)

1-1: LGTM: datetime import alias is appropriate

Using import datetime as dt keeps call sites concise and readable. No issues.


32-36: Good call removing redundant @Property for peso1

Keeping only @computed_field preserves serialization while avoiding duplication. Backward compatibility is maintained via attribute access.

…nacimiento_to_date and update is_potential_false_positive to matches_data with improved logic
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🔭 Outside diff range comments (1)
quienesquien/person.py (1)

51-56: Explicitly handle key collisions when lowercasing model_extra

The current comprehension

lowercase_extra = {
    k.lower(): v for k, v in self.model_extra.items()
}

will silently overwrite values if the payload contains both "FOO" and "foo". You should make the behavior deterministic (e.g. first-wins) or fail fast to avoid hidden data loss.

Locations to update:

  • quienesquien/person.py: lines 51–56

Example “first-wins” patch:

-            lowercase_extra = {
-                k.lower(): v for k, v in self.model_extra.items()
-            }
+            lowercase_extra = {}
+            for k, v in self.model_extra.items():
+                lk = k.lower()
+                # keep the first occurrence; ignore any later collisions
+                if lk in lowercase_extra:
+                    continue
+                lowercase_extra[lk] = v
             self.model_extra.clear()
             self.model_extra.update(lowercase_extra)

If you’d rather raise on duplicates, let me know and I can provide a ValueError variant.

♻️ Duplicate comments (1)
quienesquien/person.py (1)

58-67: Semantics of matches_data align with prior review consensus

Returns False only on mismatches when both sides are present; otherwise True. This matches the agreed behavior for partial data availability.

🧹 Nitpick comments (4)
quienesquien/person.py (2)

37-46: Consider caching and narrowing the exception scope in fecha_nacimiento_to_date

  • Avoid re-parsing the same string on each access by using @cached_property (date is immutable post-init).
  • Since you already guard with if not self.fecha_nacimiento, catching ValueError is sufficient (TypeError should not occur).

Apply this diff within the selected lines:

-    @property
+    @cached_property
     def fecha_nacimiento_to_date(self) -> dt.date | None:
@@
-        except (TypeError, ValueError):
+        except ValueError:
             return None

And add this import at the top of the file:

from functools import cached_property

61-66: Simplify nested conditionals and avoid recomputing the date property

Streamlines logic per Ruff SIM102 and avoids repeating the property computation.

-        if date_of_birth and self.fecha_nacimiento_to_date:
-            if self.fecha_nacimiento_to_date != date_of_birth:
-                return False
-        if curp and self.curp:
-            if curp != self.curp:
-                return False
+        dob = self.fecha_nacimiento_to_date
+        if date_of_birth and dob and dob != date_of_birth:
+            return False
+        if curp and self.curp and curp != self.curp:
+            return False
tests/test_person.py (2)

23-26: Strengthen assertions to verify uppercase keys are removed

In addition to checking lowercase entries, assert uppercase keys aren’t present post-normalization.

     assert person.model_extra['campo_extra1'] == 'valor1'
     assert person.model_extra['campo_extra2'] == 'valor2'
+    assert 'CAMPO_EXTRA1' not in person.model_extra
+    assert 'CAMPO_EXTRA2' not in person.model_extra

41-55: Nit: rename test to mirror property name

Align test name with fecha_nacimiento_to_date for consistency and easier grep.

-def test_fecha_nacimiento_date(
+def test_fecha_nacimiento_to_date(
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these settings in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 2c9bf61 and 0a8242b.

📒 Files selected for processing (3)
  • quienesquien/person.py (3 hunks)
  • quienesquien/version.py (1 hunks)
  • tests/test_person.py (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • quienesquien/version.py
🧰 Additional context used
📓 Path-based instructions (1)
**/*.py

⚙️ CodeRabbit Configuration File

**/*.py: Enforce Relative Imports for Internal Modules

Ensure that any imports referencing internal modules use relative paths. However, if modules reside in the main module directories (for example /src or /library_or_app_name) —and relative imports are not feasible—absolute imports are acceptable. Additionally, if a module is located outside the main module structure (for example, in /tests or /scripts at a similar level), absolute imports are also valid.

Examples and Guidelines:

  1. If a module is in the same folder or a subfolder of the current file, use relative imports. For instance: from .some_module import SomeClass
  2. If the module is located under /src or /library_or_app_name and cannot be imported relatively, absolute imports are allowed (e.g., from library_or_app_name.utilities import helper_method).
  3. If a module is outside the main module directories (for example, in /tests, /scripts, or any similarly placed directory), absolute imports are valid.
  4. External (third-party) libraries should be imported absolutely (e.g., import requests).

**/*.py:
Rule: Enforce Snake Case in Python Backend

  1. New or Modified Code: Use snake_case for all variables, functions, methods, and class attributes.
  2. Exceptions (Pydantic models for API responses):
    • Primary fields must be snake_case.
    • If older clients expect camelCase, create a computed or alias field that references the snake_case field.
    • Mark any camelCase fields as deprecated or transitional.

Examples

Invalid:

class CardConfiguration(BaseModel):
    title: str
    subTitle: str  # ❌ Modified or new field in camelCase

Valid:

class CardConfiguration(BaseModel):
    title: str
    subtitle: str  # ✅ snake_case for new/modified field

    @computed_field
    def subTitle(self) -> str:  # camelCase allowed only for compatibility
        return self.subtitle

Any direct use of camelCase in new or updated code outside of these exceptions should be flagged.

`*...

Files:

  • quienesquien/person.py
  • tests/test_person.py
🧬 Code Graph Analysis (1)
tests/test_person.py (1)
quienesquien/person.py (3)
  • Person (12-67)
  • fecha_nacimiento_to_date (38-46)
  • matches_data (58-67)
🪛 Ruff (0.12.2)
quienesquien/person.py

61-62: Use a single if statement instead of nested if statements

(SIM102)


64-65: Use a single if statement instead of nested if statements

Combine if statements using and

(SIM102)

🔇 Additional comments (5)
quienesquien/person.py (2)

1-1: LGTM: explicit datetime import is appropriate

Using import datetime as dt is clear and consistent with usage across the file.


32-36: LGTM: peso1 as a Pydantic @computed_field

This keeps backward compatibility while avoiding persisting the field. The return type str matches the intended behavior.

tests/test_person.py (3)

1-4: LGTM: test imports and typing

Parametrization via pytest and explicit typing improve clarity and static checking.


9-16: LGTM: type-hinted test function

The explicit return type and typed dict[str, Any] support tooling (mypy/ruff).


57-132: LGTM: comprehensive coverage for matches_data

Great matrix of cases for both DOB and CURP, including presence/absence conditions. This aligns well with the method’s intended semantics.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (5)
quienesquien/person.py (3)

37-46: Consider trimming whitespace before parsing fecha_nacimiento

Real-world feeds often include leading/trailing spaces. Trimming improves robustness without changing semantics. Also keeps None on empty strings post-trim.

Apply this diff:

 @property
 def fecha_nacimiento_to_date(self) -> dt.date | None:
-    if not self.fecha_nacimiento:
+    if not self.fecha_nacimiento:
         return None
     try:
-        return dt.datetime.strptime(
-            self.fecha_nacimiento, '%d/%m/%Y'
-        ).date()
+        value = self.fecha_nacimiento.strip()
+        if not value:
+            return None
+        return dt.datetime.strptime(value, '%d/%m/%Y').date()
     except (TypeError, ValueError):
         return None

48-56: Lowercasing extra keys may cause collisions (potential data loss)

If two extras differ only by case (e.g., FOO and foo), one will overwrite the other after lowercasing. If this scenario is possible, define a collision policy (keep-first, keep-last, or aggregate) and cover it with a test.

I can propose an implementation that preserves first value and records collisions under a reserved key (e.g., case_collisions). Let me know if you want that diff.


58-64: Verify business rule for “no data available” and make CURP comparison resilient

Current logic returns False when neither side has data or when only inputs or only model have data. That matches the new tests but diverges from the earlier discussion where “no data” might still be considered a possible match. Please confirm the intended behavior.

Additionally, CURP comparison will often be case-insensitive and may include stray spaces. Normalizing both sides improves match reliability.

Apply this diff to normalize CURP (non-breaking for current tests, but more robust):

 def matches_data(
     self, date_of_birth: dt.date | None = None, curp: str | None = None
 ) -> bool:
     dob = self.fecha_nacimiento_to_date
-    match_dob = bool(dob and dob == date_of_birth)
-    match_curp = bool(self.curp and self.curp == curp)
+    match_dob = bool(dob and dob == date_of_birth)
+    curp_val = (self.curp or "").strip().upper()
+    curp_in = (curp or "").strip().upper()
+    match_curp = bool(curp_val and curp_in and curp_val == curp_in)
     return match_dob or match_curp

If the intended behavior is to consider “no data available” as a possible match, we can adjust the return accordingly and update tests. I can draft that variant too.

tests/test_person.py (2)

29-55: Optionally add a whitespace case for fecha_nacimiento parsing

If you adopt trimming in fecha_nacimiento_to_date, include a case with leading/trailing spaces to lock the behavior.

Apply this diff after adopting the parsing change:

 @pytest.mark.parametrize(
     'fecha_nacimiento_input, expected_date',
     [
         ('13/11/1953', dt.date(1953, 11, 13)),
+        (' 13/11/1953 ', dt.date(1953, 11, 13)),
         (None, None),
         ('', None),
         ('invalid-date', None),
         ('1953-11-13', None),
         ('13/11', None),
         ('13-11-1953', None),
     ],
 )

57-109: Parameterization is thorough; consider case-insensitive CURP test if you normalize

The matrix covers key scenarios, including mismatches and missing data. If you normalize CURP to be case-insensitive, add a test with mixed case to prevent regressions.

Example to add (only if code is updated to normalize CURP):

         # Same CURPs
         (None, 'LOOA531113HDFPBR07', None, 'LOOA531113HDFPBR07', True),
+        # Same CURP with different case and surrounding spaces (normalized)
+        (None, 'looa531113hdfpbr07', None, '  LOOA531113HDFPBR07 ', True),
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 0a8242b and 1f66684.

📒 Files selected for processing (3)
  • quienesquien/person.py (3 hunks)
  • quienesquien/version.py (1 hunks)
  • tests/test_person.py (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • quienesquien/version.py
🧰 Additional context used
📓 Path-based instructions (1)
**/*.py

⚙️ CodeRabbit Configuration File

**/*.py: Enforce Relative Imports for Internal Modules

Ensure that any imports referencing internal modules use relative paths. However, if modules reside in the main module directories (for example /src or /library_or_app_name) —and relative imports are not feasible—absolute imports are acceptable. Additionally, if a module is located outside the main module structure (for example, in /tests or /scripts at a similar level), absolute imports are also valid.

Examples and Guidelines:

  1. If a module is in the same folder or a subfolder of the current file, use relative imports. For instance: from .some_module import SomeClass
  2. If the module is located under /src or /library_or_app_name and cannot be imported relatively, absolute imports are allowed (e.g., from library_or_app_name.utilities import helper_method).
  3. If a module is outside the main module directories (for example, in /tests, /scripts, or any similarly placed directory), absolute imports are valid.
  4. External (third-party) libraries should be imported absolutely (e.g., import requests).

**/*.py:
Rule: Enforce Snake Case in Python Backend

  1. New or Modified Code: Use snake_case for all variables, functions, methods, and class attributes.
  2. Exceptions (Pydantic models for API responses):
    • Primary fields must be snake_case.
    • If older clients expect camelCase, create a computed or alias field that references the snake_case field.
    • Mark any camelCase fields as deprecated or transitional.

Examples

Invalid:

class CardConfiguration(BaseModel):
    title: str
    subTitle: str  # ❌ Modified or new field in camelCase

Valid:

class CardConfiguration(BaseModel):
    title: str
    subtitle: str  # ✅ snake_case for new/modified field

    @computed_field
    def subTitle(self) -> str:  # camelCase allowed only for compatibility
        return self.subtitle

Any direct use of camelCase in new or updated code outside of these exceptions should be flagged.

`*...

Files:

  • tests/test_person.py
  • quienesquien/person.py
🧬 Code Graph Analysis (1)
tests/test_person.py (1)
quienesquien/person.py (3)
  • Person (12-64)
  • fecha_nacimiento_to_date (38-46)
  • matches_data (58-64)
🔇 Additional comments (2)
quienesquien/person.py (1)

32-35: Good change: use only @computed_field for peso1

Dropping the redundant @Property and keeping a computed field is the right call for Pydantic v2. The implementation is clear and type-safe.

tests/test_person.py (1)

9-27: Tests correctly reflect lowercase normalization of model_extra

Good update to assert against model_extra with lowercase keys and to type the test for MyPy.

@gmorales96 gmorales96 merged commit 650036b into master Aug 22, 2025
10 checks passed
@gmorales96 gmorales96 deleted the enhancement-qeq-integration branch August 22, 2025 19:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants