Skip to content

fix(resolver): handle None result.service from getnameinfo()#12392

Open
rnagulapalle wants to merge 3 commits intoaio-libs:masterfrom
rnagulapalle:fix/resolver-service-none-mypy
Open

fix(resolver): handle None result.service from getnameinfo()#12392
rnagulapalle wants to merge 3 commits intoaio-libs:masterfrom
rnagulapalle:fix/resolver-service-none-mypy

Conversation

@rnagulapalle
Copy link
Copy Markdown

Summary

getnameinfo() returns a NameinfoResult where .service is typed as str | None. The existing code passes it directly to int() which mypy correctly rejects:

aiohttp/resolver.py:131:32: error: Argument 1 to "int" has incompatible type "str | None"; expected "str | Buffer | SupportsInt | SupportsIndex | SupportsTrunc"  [arg-type]

Fix

Fall back to the original numeric port from the address tuple when result.service is None:

# Before
port = int(result.service)

# After
port = int(result.service) if result.service is not None else address[1]

This matches the pattern already used in the non-link-local IPv6 path and the IPv4 path (both use address[1] directly).

Test plan

  • Existing resolver tests pass
  • mypy check on aiohttp/resolver.py passes with no arg-type errors

N3XT3R1337 and others added 2 commits March 18, 2026 11:43
getnameinfo() returns a NameinfoResult where service is typed as
str | None. Passing None directly to int() fails mypy's arg-type
check. Fall back to the original numeric port when service is None.

Fixes mypy error: Argument 1 to "int" has incompatible type
"str | None"; expected "str | Buffer | SupportsInt | ..."
@psf-chronographer psf-chronographer bot added the bot:chronographer:provided There is a change note present in this PR label Apr 19, 2026
@rnagulapalle
Copy link
Copy Markdown
Author

Closing — will be re-raised by Phalanx CI Fixer autonomously.

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 19, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.92%. Comparing base (438cb40) to head (4459e6e).
⚠️ Report is 209 commits behind head on master.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #12392      +/-   ##
==========================================
- Coverage   99.11%   98.92%   -0.19%     
==========================================
  Files         130      134       +4     
  Lines       45432    46639    +1207     
  Branches     2400     2429      +29     
==========================================
+ Hits        45028    46137    +1109     
- Misses        273      373     +100     
+ Partials      131      129       -2     
Flag Coverage Δ
CI-GHA 98.98% <100.00%> (+0.01%) ⬆️
OS-Linux 98.72% <100.00%> (+0.01%) ⬆️
OS-Windows 96.98% <100.00%> (-0.01%) ⬇️
OS-macOS 97.88% <100.00%> (+0.01%) ⬆️
Py-3.10.11 97.39% <100.00%> (-0.03%) ⬇️
Py-3.10.20 97.86% <100.00%> (-0.03%) ⬇️
Py-3.11.15 98.11% <100.00%> (+0.02%) ⬆️
Py-3.11.9 97.65% <100.00%> (+0.02%) ⬆️
Py-3.12.10 97.73% <100.00%> (+0.02%) ⬆️
Py-3.12.13 98.20% <100.00%> (+0.01%) ⬆️
Py-3.13.12 ?
Py-3.13.13 98.45% <100.00%> (?)
Py-3.14.3 ?
Py-3.14.3t ?
Py-3.14.4 98.51% <100.00%> (?)
Py-3.14.4t 97.51% <100.00%> (?)
Py-pypy3.11.13-7.3.20 ?
Py-pypy3.11.15-7.3.21 97.35% <100.00%> (?)
VM-macos 97.88% <100.00%> (+0.01%) ⬆️
VM-ubuntu 98.72% <100.00%> (+0.01%) ⬆️
VM-windows 96.98% <100.00%> (-0.01%) ⬇️
cython-coverage 38.17% <3.70%> (?)

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.

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Apr 19, 2026

Merging this PR will not alter performance

✅ 67 untouched benchmarks
⏩ 4 skipped benchmarks1


Comparing rnagulapalle:fix/resolver-service-none-mypy (4459e6e) with master (53f6e91)

Open in CodSpeed

Footnotes

  1. 4 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@rnagulapalle rnagulapalle reopened this Apr 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:chronographer:provided There is a change note present in this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants